import { Router } from 'express';
import { body } from 'express-validator';
import { DifyAIController } from '../../api/controllers/difyAIController';
import { authenticateClient } from '../../middleware/auth';
import { validateRequest } from '../../middleware/validation';
import { uploadAudio } from '../../middleware/upload';

const router = Router();
const difyAIController = new DifyAIController();

/**
 * @swagger
 * /api/client/dify-ai/voice-to-text:
 *   post:
 *     summary: 语音转文字
 *     description: |
 *       将上传的音频文件转换为文字内容，支持多种音频格式。
 *       
 *       **支持的音频格式：**
 *       - MP3 (.mp3) - 最常用的压缩格式
 *       - WAV (.wav) - 无损音频格式
 *       - M4A (.m4a) - Apple 音频格式
 *       - AAC (.aac) - 高质量压缩格式
 *       
 *       **文件限制：**
 *       - 最大文件大小：10MB
 *       - 最大音频时长：5分钟
 *       - 采样率：16kHz 或 44.1kHz
 *       - 比特率：128kbps 或更高
 *       
 *       **使用场景：**
 *       - 语音输入查询
 *       - 语音命令识别
 *       - 会议记录转写
 *       - 语音笔记转换
 *       
 *       **注意事项：**
 *       - 音频质量越高，识别准确率越高
 *       - 建议在安静环境下录制
 *       - 支持中文、英文等多种语言
 *       - 如果遇到格式错误，请转换为 MP3 或 WAV 格式
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             required:
 *               - audio
 *             properties:
 *               audio:
 *                 type: string
 *                 format: binary
 *                 description: 音频文件（推荐使用 MP3 或 WAV 格式）
 *                 example: "voice_message.mp3"
 *     responses:
 *       200:
 *         description: 转换成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                   description: 响应状态码
 *                 message:
 *                   type: string
 *                   example: "语音转文字成功"
 *                   description: 响应消息
 *                 data:
 *                   type: object
 *                   properties:
 *                     text:
 *                       type: string
 *                       description: 转换后的文字内容
 *                       example: "你好，我想了解一下音乐节的信息"
 *                       maxLength: 10000
 *                     confidence:
 *                       type: number
 *                       format: float
 *                       description: 识别置信度（0-1之间）
 *                       example: 0.95
 *                     duration:
 *                       type: number
 *                       description: 音频时长（秒）
 *                       example: 3.5
 *                     language:
 *                       type: string
 *                       description: 检测到的语言代码
 *                       example: "zh-CN"
 *                     segments:
 *                       type: array
 *                       description: 分段识别结果（适用于长音频）
 *                       items:
 *                         type: object
 *                         properties:
 *                           start:
 *                             type: number
 *                             description: 开始时间（秒）
 *                           end:
 *                             type: number
 *                             description: 结束时间（秒）
 *                           text:
 *                             type: string
 *                             description: 该时间段的文字内容
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *                   description: 响应时间戳
 *       400:
 *         description: 请求参数错误
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 400
 *                 message:
 *                   type: string
 *                   example: "请上传音频文件"
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *       401:
 *         description: 未授权访问
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权访问"
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *       413:
 *         description: 文件过大
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 413
 *                 message:
 *                   type: string
 *                   example: "音频文件过大，请上传小于10MB的文件"
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *       415:
 *         description: 不支持的媒体类型
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 415
 *                 message:
 *                   type: string
 *                   example: "音频文件格式不支持，请转换为 MP3 或 WAV 格式"
 *                 details:
 *                   type: object
 *                   properties:
 *                     supportedFormats:
 *                       type: array
 *                       items:
 *                         type: string
 *                       description: 支持的音频格式列表
 *                       example: ["MP3", "WAV", "M4A", "AAC"]
 *                     recommendedFormat:
 *                       type: string
 *                       description: 推荐的音频格式
 *                       example: "MP3"
 *                     conversionTools:
 *                       type: array
 *                       items:
 *                         type: string
 *                       description: 推荐的格式转换工具
 *                       example: ["FFmpeg", "在线转换工具", "音频编辑软件"]
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *       422:
 *         description: 音频文件无效
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 422
 *                 message:
 *                   type: string
 *                   example: "音频文件损坏或无法解析，请重新上传"
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *       429:
 *         description: 请求过于频繁
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 429
 *                 message:
 *                   type: string
 *                   example: "请求过于频繁，请稍后再试"
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *       500:
 *         description: 服务器内部错误
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 500
 *                 message:
 *                   type: string
 *                   example: "语音转文字服务暂时不可用，请稍后再试"
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *       503:
 *         description: 服务不可用
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 503
 *                 message:
 *                   type: string
 *                   example: "AI语音识别服务暂时不可用，请稍后再试"
 *                 timestamp:
 *                   type: string
 *                   format: date-time
 *     x-codegen-request-body-name: body
 *     x-codegen-samples:
 *       - lang: 'JavaScript'
 *         source: |
 *           const formData = new FormData();
 *           formData.append('audio', audioFile);
 *           
 *           const response = await fetch('/api/client/dify-ai/voice-to-text', {
 *             method: 'POST',
 *             headers: {
 *               'Authorization': `Bearer ${token}`
 *             },
 *             body: formData
 *           });
 *           
 *           const result = await response.json();
 *           console.log('识别结果:', result.data.text);
 *       - lang: 'Python'
 *         source: |
 *           import requests
 *           
 *           with open('audio.mp3', 'rb') as f:
 *               files = {'audio': f}
 *               headers = {'Authorization': f'Bearer {token}'}
 *               response = requests.post(
 *                   '/api/client/dify-ai/voice-to-text',
 *                   files=files,
 *                   headers=headers
 *               )
 *           
 *           result = response.json()
 *           print('识别结果:', result['data']['text'])
 *       - lang: 'cURL'
 *         source: |
 *           curl -X POST "http://localhost:3000/api/client/dify-ai/voice-to-text" \
 *             -H "Authorization: Bearer YOUR_TOKEN" \
 *             -F "audio=@voice_message.mp3"
 *       - lang: '音频格式转换'
 *         source: |
 *           # 使用 FFmpeg 转换音频格式
 *           ffmpeg -i input.audio -acodec mp3 -ar 16000 -ac 1 output.mp3
 *           
 *           # 转换为 WAV 格式
 *           ffmpeg -i input.audio -acodec pcm_s16le -ar 16000 -ac 1 output.wav
 *           
 *           # 在线转换工具推荐
 *           # - https://convertio.co/audio-converter/
 *           # - https://www.onlinevideoconverter.com/
 *           # - https://audio.online-convert.com/
 */
router.post('/voice-to-text', [
  authenticateClient,
  uploadAudio
], difyAIController.voiceToText);

/**
 * @swagger
 * /api/client/dify-ai/aliyun-voice-to-text:
 *   post:
 *     summary: 阿里云语音转文字
 *     description: |
 *       使用阿里云实时语音识别服务将音频文件转换为文字内容。
 *       
 *       **支持的音频格式：**
 *       - MP3 (.mp3) - 最常用的压缩格式
 *       - WAV (.wav) - 无损音频格式
 *       - M4A (.m4a) - Apple 音频格式
 *       - AAC (.aac) - 高质量压缩格式
 *       - PCM (.pcm) - 原始音频格式
 *       
 *       **文件限制：**
 *       - 最大文件大小：100MB
 *       - 支持多种采样率：16kHz, 44.1kHz 等
 *       - 支持中文、英文等多种语言
 *       
 *       **优势：**
 *       - 高识别准确率
 *       - 支持实时识别
 *       - 支持标点符号
 *       - 支持语音检测
 *       
 *       **注意事项：**
 *       - 需要配置阿里云访问密钥
 *       - 建议在安静环境下录制
 *       - 音频质量越高，识别准确率越高
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             required:
 *               - audio
 *             properties:
 *               audio:
 *                 type: string
 *                 format: binary
 *                 description: 音频文件
 *     responses:
 *       200:
 *         description: 转换成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "阿里云语音转文字成功"
 *                 data:
 *                   type: object
 *                   properties:
 *                     text:
 *                       type: string
 *                       description: 转换后的文字内容
 *                     confidence:
 *                       type: number
 *                       description: 识别置信度
 *                     duration:
 *                       type: number
 *                       description: 音频时长（秒）
 *                     fileInfo:
 *                       type: object
 *                       description: 文件信息
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务内部错误
 */
router.post('/aliyun-voice-to-text', [
  authenticateClient,
  uploadAudio
], difyAIController.aliyunVoiceToText);

/**
 * @swagger
 * /api/client/dify-ai/aliyun-stream-voice-to-text:
 *   post:
 *     summary: 阿里云流式语音转文字
 *     description: |
 *       使用阿里云流式语音识别服务进行实时语音转文字。
 *       支持流式响应，可以实时获取识别结果。
 *       
 *       **特点：**
 *       - 实时识别
 *       - 流式响应
 *       - 低延迟
 *       - 支持长音频
 *       
 *       **使用场景：**
 *       - 实时语音输入
 *       - 会议记录
 *       - 语音直播
 *       - 客服系统
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 流式识别开始
 *         content:
 *           text/event-stream:
 *             schema:
 *               type: object
 *               properties:
 *                 type:
 *                   type: string
 *                   description: 事件类型
 *                 text:
 *                   type: string
 *                   description: 识别结果
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务内部错误
 */
router.post('/aliyun-stream-voice-to-text', [
  authenticateClient
], difyAIController.aliyunStreamVoiceToText);

/**
 * @swagger
 * /api/client/dify-ai/text-to-voice:
 *   post:
 *     summary: 文字转语音
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             required:
 *               text:
 *                 type: string
 *                 description: 要转换的文字内容
 *             properties:
 *               messageId:
 *                 type: string
 *                 description: 消息ID（可选）
 *     responses:
 *       200:
 *         description: 转换成功
 *         content:
 *           audio/wav:
 *             schema:
 *               type: string
 *               format: binary
 *               description: 生成的音频文件
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权
 */
router.post('/text-to-voice', [
  authenticateClient,
  body('text')
    .notEmpty()
    .withMessage('文字内容不能为空'),
  validateRequest
], difyAIController.textToVoice);

/**
 * @swagger
 * /api/client/dify-ai/history:
 *   get:
 *     summary: 获取聊天历史
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *         description: 页码
 *       - in: query
 *         name: pageSize
 *         schema:
 *           type: integer
 *         description: 每页数量
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取聊天历史成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     items:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: string
 *                           conversationId:
 *                             type: string
 *                           messageType:
 *                             type: string
 *                           content:
 *                             type: string
 *                           createdAt:
 *                             type: string
 *                             format: date-time
 *                     pagination:
 *                       type: object
 *                       properties:
 *                         total:
 *                           type: integer
 *                         page:
 *                           type: integer
 *                         pageSize:
 *                           type: integer
 *                         totalPages:
 *                           type: integer
 *       401:
 *         description: 未授权
 */
router.get('/history', authenticateClient, difyAIController.getChatHistory);

/**
 * @swagger
 * /api/client/dify-ai/app-info:
 *   get:
 *     summary: 获取Dify应用信息
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取应用信息成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     appId:
 *                       type: string
 *                       description: 应用ID
 *                     name:
 *                       type: string
 *                       description: 应用名称
 *                     description:
 *                       type: string
 *                       description: 应用描述
 *                     mode:
 *                       type: string
 *                       description: 应用模式
 *                     icon:
 *                       type: string
 *                       description: 应用图标
 *       401:
 *         description: 未授权
 */
router.get('/app-info', authenticateClient, difyAIController.getAppInfo);

/**
 * @swagger
 * /api/client/dify-ai/app-parameters:
 *   get:
 *     summary: 获取Dify应用参数
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取应用参数成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     parameters:
 *                       type: object
 *                       description: 应用参数配置
 *       401:
 *         description: 未授权
 */
router.get('/app-parameters', authenticateClient, difyAIController.getAppParameters);

/**
 * @swagger
 * /api/client/dify-ai/quick-actions:
 *   get:
 *     summary: 获取快捷操作
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取快捷操作成功
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: string
 *                         description: 操作ID
 *                       title:
 *                         type: string
 *                         description: 操作标题
 *                       description:
 *                         type: string
 *                         description: 操作描述
 *                       icon:
 *                         type: string
 *                         description: 图标名称
 *                       action:
 *                         type: string
 *                         description: 操作类型
 *                       color:
 *                         type: string
 *                         description: 颜色代码
 *       401:
 *         description: 未授权
 */
router.get('/quick-actions', authenticateClient, difyAIController.getQuickActions);

/**
 * @swagger
 * /api/client/dify-ai/stop-response:
 *   post:
 *     summary: 停止AI响应
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               taskId:
 *                 type: string
 *                 description: 任务ID
 *     responses:
 *       200:
 *         description: 停止成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 停止响应成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     success:
 *                       type: boolean
 *                       description: 是否成功停止
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权
 */
router.post('/stop-response', [
  authenticateClient,
  body('taskId')
    .notEmpty()
    .withMessage('任务ID不能为空'),
  validateRequest
], difyAIController.stopResponse);

/**
 * @swagger
 * /api/client/dify-ai/workflow-chat:
 *   post:
 *     summary: Dify Workflow 聊天 - Blocking 模式
 *     description: 与 Dify Workflow 进行智能对话，使用 blocking 模式等待完整响应，支持文件上传
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             required:
 *               - message
 *             properties:
 *               message:
 *                 type: string
 *                 description: 聊天消息内容
 *                 example: "你好，请介绍一下音乐节"
 *               conversationId:
 *                 type: string
 *                 description: 会话ID（可选，用于继续对话）
 *                 example: "conv_123456789"
 *               inputs:
 *                 type: string
 *                 description: 输入参数（JSON字符串格式）
 *                 example: '{"context": "音乐节信息查询", "user_preference": "摇滚音乐"}'
 *               responseMode:
 *                 type: string
 *                 enum: [blocking]
 *                 description: 响应模式，固定为 blocking
 *                 default: blocking
 *               files:
 *                 type: string
 *                 format: binary
 *                 description: 上传的文件（支持图片等）
 *     responses:
 *       200:
 *         description: Workflow 执行成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "Workflow 执行完成"
 *                 data:
 *                   type: object
 *                   properties:
 *                     answer:
 *                       type: string
 *                       description: AI 回复内容
 *                     conversation_id:
 *                       type: string
 *                       description: 会话ID
 *                     message_id:
 *                       type: string
 *                       description: 消息ID
 *                     task_id:
 *                       type: string
 *                       description: 任务ID
 *                     metadata:
 *                       type: object
 *                       description: 元数据信息
 *                     usage:
 *                       type: object
 *                       description: 使用统计
 *                     inputs:
 *                       type: object
 *                       description: 输入参数
 *                     response_mode:
 *                       type: string
 *                       description: 响应模式
 *       400:
 *         description: 请求参数错误
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 400
 *                 message:
 *                   type: string
 *                   example: "消息内容不能为空"
 *       401:
 *         description: 未授权访问
 *       500:
 *         description: 服务器内部错误
 */
router.post('/workflow-chat', [
  authenticateClient,
  uploadAudio, // 添加文件上传中间件
  body('message')
    .notEmpty()
    .withMessage('消息内容不能为空'),
  validateRequest
], difyAIController.workflowChat);

/**
 * @swagger
 * /api/client/dify-ai/messages/{message_id}/suggested:
 *   get:
 *     summary: 获取下一轮建议问题列表
 *     description: 根据消息ID获取AI建议的下一轮问题列表
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: message_id
 *         required: true
 *         schema:
 *           type: string
 *         description: 消息ID
 *         example: "msg_123456789"
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "获取建议问题成功"
 *                 data:
 *                   type: object
 *                   properties:
 *                     suggested_questions:
 *                       type: array
 *                       items:
 *                         type: string
 *                       description: 建议问题列表
 *                       example: ["问题1", "问题2", "问题3"]
 *                     message_id:
 *                       type: string
 *                       description: 消息ID
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权访问
 *       404:
 *         description: 消息不存在
 *       500:
 *         description: 服务器内部错误
 */
router.get('/messages/:message_id/suggested', authenticateClient, difyAIController.getSuggestedQuestions);

/**
 * @swagger
 * /api/client/dify-ai/chat:
 *   post:
 *     summary: Dify AI 聊天对话
 *     description: 与 Dify AI 助手进行智能对话，支持文本消息和文件上传，返回流式响应
 *     tags: [Dify AI助手]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             required:
 *               - message
 *             properties:
 *               message:
 *                 type: string
 *                 description: 聊天消息内容
 *                 example: "你好，请介绍一下音乐节"
 *               conversationId:
 *                 type: string
 *                 description: 会话ID（可选，用于继续对话）
 *                 example: "conv_123456789"
 *               inputs:
 *                 type: string
 *                 description: 输入参数（JSON字符串格式）
 *                 example: '{"context": "音乐节信息查询"}'
 *               responseMode:
 *                 type: string
 *                 enum: [blocking, streaming]
 *                 description: 响应模式，默认为 streaming
 *                 default: streaming
 *               files:
 *                 type: string
 *                 format: binary
 *                 description: 上传的文件（支持图片等）
 *     responses:
 *       200:
 *         description: 聊天成功，返回流式响应
 *         content:
 *           text/event-stream:
 *             schema:
 *               type: string
 *               description: Server-Sent Events 流式响应
 *             examples:
 *               start:
 *                 summary: 开始响应
 *                 value: 'data: {"type": "start", "message": "开始生成回复..."}'
 *               chunk:
 *                 summary: 部分响应
 *                 value: 'data: {"type": "chunk", "message": "部分回复内容"}'
 *               end:
 *                 summary: 完整响应
 *                 value: 'data: {"type": "end", "message": "完整的AI回复内容"}'
 *               error:
 *                 summary: 错误响应
 *                 value: 'data: {"type": "error", "message": "错误信息"}'
 *       400:
 *         description: 请求参数错误
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 400
 *                 message:
 *                   type: string
 *                   example: "消息内容不能为空"
 *       401:
 *         description: 未授权访问
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权访问"
 *       500:
 *         description: 服务器内部错误
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 500
 *                 message:
 *                   type: string
 *                   example: "AI服务暂时不可用"
 */
router.post('/chat', [
  authenticateClient,
  uploadAudio
], difyAIController.chat);

export default router;
